package com.guit.hrms.mapper;

import com.guit.hrms.po.academy.Academy;
import com.guit.hrms.po.interview.Interviewee;
import com.guit.hrms.po.position.Position;
import com.guit.hrms.po.academy.PlanAcademyJob;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AcademyMapper {


    /**
     *新增二级学院
     * @param academy
     */
    @Insert("insert into " +
            "academy(academy_number, academy_parent_id, academy_name, " +
            "academy_manager_id, academy_profile, academy_level, " +
            "create_time, update_time)" +
            "values(#{academyNumber},#{academyParentId},#{academyName}," +
            "#{academyManagerId},#{academyProfile},#{academyLevel}," +
            "#{createTime},#{updateTime})")
    void addAcademy(Academy academy);

    /**
     * 查询所有二级学院
     * @return
     */
    @Select("select * from academy")
    List<Academy> getAcademy();

    /**
     * 更新二级学院
     * @param academy
     */
    void updateAcademy(Academy academy);

    /**
     * 根据id删除二级学院
     * @param academyId
     */
    @Delete("delete from academy where academy_id = #{academyId}")
    void deleteAcademyById(Integer academyId);

    /**
     * 根据父id删除二级学院
     * @param academyId
     */
    @Delete("delete from academy where academy_parent_id = #{academyId}")
    void deleteAcademyByParentId(Integer academyId);

    /**
     * 查询所有二级学院及其岗位
     * @return
     */
    @Select("SELECT * FROM academy")
    List<Academy> getAcademyWithPositions();
    
    /**
     * 根据二级学院id查询其岗位
     * @param academyId
     * @return
     */
    @Select("SELECT * FROM positions WHERE dept_type = 2 AND dept_id = #{academyId}")
    List<Position> getPositionsByAcademyId(Integer academyId);

    /**
     * 根据学院编号查询学院
     * @param numbering
     * @return
     */
    @Select("select *from academy where academy_number = #{numbering}")
    Academy getAcademyByDeptNumber(String numbering);

    /**
     * 根据学院编号查询学院
     * @param academyId
     * @return
     */
    @Select("select *from academy where academy_id = #{academyId}")
    Academy getAcademyById(Integer academyId);

    /**
     * 根据主键查询学院中间表
     * @param interviewee
     * @return
     */
    @Select("select * from plan_academy_job where plan_id = #{planId} and academy_id =#{deptId} and position_number = #{positionNumber}")
    PlanAcademyJob getPlanAcademyJobByPrimaryKey(Interviewee interviewee);
}
